//
//  MYGMinAuthController.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/11.
//

import UIKit

class MYGMinAuthView: UIView {

    // MARK: - init
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI() {
        self.layer .backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor
        addSubview(bgView)
        
        bgView.addSubview(titleLabel)
        bgView.addSubview(closeButton)
        
        bgView.addSubview(nameLabel)
        bgView.addSubview(perButton)
        bgView.addSubview(fansButton)
        bgView.addSubview(followButton)
        bgView.addSubview(sickButton)
        bgView.addSubview(fixButton)
      
        
        bgView.snp.makeConstraints { make in
            make.right.left.bottom.equalToSuperview()
            make.height.equalTo(264)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(16)
        }
        closeButton.snp.makeConstraints { make in
            make.width.height.equalTo(20)
            make.centerY.equalTo(titleLabel)
            make.right.equalToSuperview().offset(-5)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(26)
            make.top.equalTo(53)
            make.height.equalTo(22)
        }
        
        perButton.snp.makeConstraints { make in
            make.left.equalTo(37)
            make.top.equalTo(nameLabel.snp.bottom).offset(16)
            make.height.equalTo(38)
            make.width.equalTo((screenWidth-111)/2)
        }
        
        fansButton.snp.makeConstraints { make in
            make.left.equalTo(perButton.snp.right).offset(37)
            make.centerY.equalTo(perButton)
            make.width.height.equalTo(perButton)
        }
        
        followButton.snp.makeConstraints { make in
            make.centerX.equalTo(perButton)
            make.width.height.equalTo(perButton)
            make.top.equalTo(perButton.snp.bottom).offset(12)
        }
        
        sickButton.snp.makeConstraints { make in
            make.centerX.equalTo(fansButton)
            make.width.height.equalTo(perButton)
            make.top.equalTo(perButton.snp.bottom).offset(12)
        }
        
        fixButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-30)
            make.height.equalTo(20)
        }
        
        titleLabel.setContentHuggingPriority(.required, for: .vertical)
        titleLabel.setContentCompressionResistancePriority(.required, for: .vertical)
    }
    
    
    private lazy var bgView : UIView = {
        let bg = UIView()
        bg.backgroundColor = .white
        return bg
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(17)
        label.textColor = .rgba(0, 0, 0, 1)
        label.text = "不给谁看"
        return label
    }()
    
    private lazy var closeButton: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "close"), for: .normal)
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        
        return btn
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(16)
        label.textColor = .rgba(51, 51, 51, 1)
        label.text = "以下类型朋友"
        return label
    }()
    
    private lazy var perButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("陌生人", for: .normal)
        btn.setTitleColor(.rgba(151, 151, 151, 1), for: .normal)
        btn.setBackgroundColor(color: .rgba(77, 120, 237, 1), forState: .selected)
        btn.setTitleColor(.white, for: .selected)
        btn.titleLabel?.font = .regular(15)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 4.5
        btn.layer.borderWidth = 0.5
        btn.layer.borderColor = UIColor.rgba(151, 151, 151, 1).cgColor
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        
        return btn
    }()
    
    private lazy var fansButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("粉丝", for: .normal)
        btn.setTitleColor(.rgba(151, 151, 151, 1), for: .normal)
        btn.setBackgroundColor(color: .rgba(77, 120, 237, 1), forState: .selected)
        btn.setTitleColor(.white, for: .selected)
        btn.titleLabel?.font = .regular(15)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 4.5
        btn.layer.borderWidth = 0.5
        btn.layer.borderColor = UIColor.rgba(151, 151, 151, 1).cgColor
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var followButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("关注", for: .normal)
        btn.setTitleColor(.rgba(151, 151, 151, 1), for: .normal)
        btn.setBackgroundColor(color: .rgba(77, 120, 237, 1), forState: .selected)
        btn.setTitleColor(.white, for: .selected)
        btn.titleLabel?.font = .regular(15)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 4.5
        btn.layer.borderWidth = 0.5
        btn.layer.borderColor = UIColor.rgba(151, 151, 151, 1).cgColor
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var sickButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("我的患者", for: .normal)
        btn.setTitleColor(.rgba(151, 151, 151, 1), for: .normal)
        btn.setBackgroundColor(color: .rgba(77, 120, 237, 1), forState: .selected)
        btn.setTitleColor(.white, for: .selected)
        btn.titleLabel?.font = .regular(15)
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 4.5
        btn.layer.borderWidth = 0.5
        btn.layer.borderColor = UIColor.rgba(151, 151, 151, 1).cgColor
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var fixButton: UIButton = {
        let btn = UIButton()
        btn.setTitle("修改可见范围", for: .normal)
        btn.setTitleColor(.rgba(69, 131, 250, 1), for: .normal)
        btn.titleLabel?.font = .regular(14)
        btn.addTarget(self, action: #selector(clickBtn(_:)), for: .touchUpInside)
        return btn
    }()
   
    
    @objc func clickBtn(_ sender:UIButton){
        
        if sender == closeButton {
            self.removeFromSuperview()
        }
        
        if sender == perButton {
            perButton.isSelected = !perButton.isSelected
        }
        if sender == fansButton {
            fansButton.isSelected = !fansButton.isSelected
        }
        if sender == followButton {
            followButton.isSelected = !followButton.isSelected
        }
        if sender == sickButton {
            sickButton.isSelected = !sickButton.isSelected
        }
    }

}
